function hexOut = getCCs_dev(hexIn, sensorList, flightDate, FlightGUID)
  % Function for retrieving and date-validating sensor calibration
  % coefficients from the DB
  %
  % Author: David Goldsmith, Wash. State Dept. of Ecology, dgol461@ecy.wa.gov
  % Release date: N/A
  
    global DB
    
    hexOut = hexIn; % Most of hex won't be changed
    
  % "Global" list of conCClabels to ignore when comparing to list of CCs
  % coming from the DB; note: QAQC of Serial# and CalibDate performed 
  % separately
    gIgnoreList = {'SerialNumber', 'CalibrationDate', 'COMMENT',...
                   'SensorID', 'index'};
    
    qCC = query_dev(DB, struct('tbls', {{'CalibrationView'}}));
    
    for sensor = sensorList % For each sensor in sensorList
        Sensor = 'Unknown sensor'; % In case exception thrown before field
                                  % successfully determined below
        SN = 'Unkown'; % Ditto, re: serial #
        try
            s = sensor{:};
            pIgnoreList = {}; % pIgnoreList = parameter-specific conCClabels
                              % to ignore; default is an empty list
            switch s
                case 'P'
                    Sensor = 'PressureSensor';
                case 'T'
                    Sensor = 'TemperatureSensor';
                    pIgnoreList = {'A', 'B', 'C', 'D',...
                                   'F0_Old', 'Slope', 'Offset'};
                case 'C'
                    Sensor = 'ConductivitySensor';
                    pIgnoreList = {'SeriesR', 'ConductivityType', 'WBOTC',...
                                   'COMMENT', 'Coefficients', 'CellConst',...
                                   'A', 'B', 'C', 'D', 'M', 'equation',...
                                   'Slope', 'Offset', 'UseG_J'};
                case 'O'
                    Sensor = 'OxygenSensor';
                    pIgnoreList = {'CalibrationCoefficients', 'Boc', 'DO',...
                                   'Use2007Equation', 'Pcor', 'Tcor',...
                                   'Tau', 'equation'};
                case 'H'
                    Sensor = 'pH_Sensor';
                case 'X'
                    Sensor = 'TransChelseaSeatechWetlabCStarSensor';
                case 'F'
                    Sensor = 'FluoroWetlabECO_AFL_FL_Sensor';
                case 'U'
                    Sensor = 'UserPolynomialSensor';
                    pIgnoreList = {'SensorName'};
                case 'R'
                    Sensor = 'PAR_BiosphericalLicorChelseaSensor';
            end
            ignoreList = union(gIgnoreList, pIgnoreList);

          % First, just determine the latest prior calibration start date
            qCC.setPropVals('cols', {'TOP 1', 'start'}); 

          % Build query where clause
          % Match MatlabProcessingID
            equipType = ['(EquipmentTypeID=''' s ''')'];        

          % Match SerialNumberDescription
            SN = hexIn.Sensors.(Sensor).SerialNumber;
            if isnumeric(SN)
                SN = num2str(SN);
                SND = ['(SN=' SN ')'];
            else
                SN = SN';
                SND = ['(SN=''' SN ''')'];                    
            end

          % UTCCalibrationBeginDatetime should precede flightDate
            startCond = ['(start<''' flightDate{:}(1:10) ''')'];
            qCC.setPropVals('where', {[equipType ' AND ' SND ' AND '...
                                       startCond]});

          % Order descending so TOP 1 gets us latest
            orderBy = {'start', 'des'};
            qCC.setPropVals('orderBy', {orderBy});

          % Get the required date
            qCC.submitStatement
            LPS = qCC.result{:}; % Latest prior start date

          % Now requery for the coefs. matching this start date but not
          % limiting to TOP 1
            qCC.setPropVals('cols', {'CCN', 'CCQ'})
            startCond = ['(start=''' LPS ''')'];
            qCC.setPropVals('where', {[equipType ' AND ' SND ' AND '...
                                       startCond]});
            qCC.submitStatement
            resultStruct = cell2struct(qCC.result(:,2), qCC.result(:,1));

          % Now "push" CC's to their "proper" places, first comparing values
          % values to CCs from CON file for QAQC (differences are reported,
          % not acted upon)
          
            conCCs = hexIn.Sensors.(Sensor);
          % Report calib date mismatch
            if ~myDotNetDateTime.IsDateTime(LPS) || ...
               ~myDotNetDateTime.IsDateTime(conCCs.CalibrationDate') || ...
               datenum(LPS) ~= datenum(conCCs.CalibrationDate')
                saveLog_dev(['ALERT: either the calibration date in the DB '...
                         'for the ' Sensor ', SN ' SN ' does not match that '...
                         'from the CONFileBLOB associated with FlightGUID '...
                         FlightGUID ', or one (or both) of these is not a '...
                         'datetime-convertible string (this alert is advis'...
                         'ory, DB CCs will be used).  ']);
            end
            hexOut.Sensors.(Sensor).CalibrationDate = LPS;

          % Check for "extras" in the CON file
            conCompareList = setdiff(fieldnames(conCCs), ignoreList);
            for f = conCompareList
                if ~ismember(f{:}, qCC.result(:,1))
                    saveLog_dev(['ALERT: the CONFileBLOB associated with '...
                             'FlightGUID ' FlightGUID ' has calibration coef'...
                             'ficients (not specified as being ignorable) for '...
                             'the ' Sensor ', SN ' SN ' that the DB does not '...
                             'have (this alert is advisory: where they overlap, '...
                             'DB CCs will be used, otherwise, if needed, the '...
                             'CON file values will be used).  ']);
                    break
                end
            end

          % Check for "extras" in the DB, compare values (reporting discrep-
          % ancies) and assign DB values 
            for f = qCC.result(:,1)'
                f = f{:};
                if ~ismember(f, conCompareList)
                    saveLog_dev(['ALERT: CC ' f ' occurs in the DB for '...
                             'Sensor ' Sensor ', SN ' SN ' but not in the '...
                             'CONFileBLOB associated with the a correspond'...
                             'ing FlightGUID ' FlightGUID '.  ']);
                elseif resultStruct.(f) ~= conCCs.(f)
                    saveLog_dev(['ALERT: DB and FlightGUID ' FlightGUID ... 
                             ' CONFileBLOB values for ' Sensor ', SN ' SN ...
                             ' CC ' f ' do not match (this alert is advisory'...
                             ', the DB value of ' num2str(resultStruct.(f))...
                             ' will be used).  ']);
                end
                hexOut.Sensors.(Sensor).(f) = resultStruct.(f);
            end

        catch ME
            if isempty(qCC.errCode)
                msg = ['ALERT: "' ME.message '" error thrown '];
            else
                msg = ['ALERT: "' [qCC.errCode{:}] '" error '];
            end            
            saveLog_dev([msg 'trying to get latest prior calibration coef'...
                     'ficients from the DB for ' Sensor ', serial number '...
                     SN ', FlightGUID ' FlightGUID '; that sensor''s CCs '...
                     'from that flight''s CON file of record will be used.  '])
        end
    end
end